{% extends 'report.base.html' %}

{% load custom_tags %}

{% block main %}
  
  <h2>
    {% for itemname in items %}
      <span>{{itemname}}</span>
      {% if forloop.last %}
      {% else %}
      ,
      &nbsp;
      {% endif %}
    {% endfor %}

    Report
  </h2>

  <table>
    <tr>
      <th class="bg-gainsboro">Mentor</th>
      <th class="bg-gainsboro">Customer</th>
      {% for itemname in items %}
      <th class="bg-gainsboro">{{itemname}} quantity</th>
      {% endfor %}
    </tr>
    {% for row in rows %}
      <tr>
        
        {% if row.mentor == '-' %}
          <td>{{row.mentor}}</td>
        {% else %}
          {% if row.group_orders_count > 0 %}
            <td rowspan="{{row.group_orders_count}}">{{row.mentor}}</td>
          {% endif %}
        {% endif %}

        {% if row.customer == 'total' %}
          <td class="font-bold bg-gainsboro">{{row.customer}}</td>
        {% else %}
          <td>{{row.customer}}</td>
        {% endif %}

        {% for itemname in items %}
          {% with qt=row.quantity %}
            {% if row.customer == 'total' %}
              <td class="align-right font-bold bg-gainsboro">{% get_item_quantity qt itemname %}</td>
            {% else %}
              <td class="align-right">{% get_item_quantity qt itemname %}</td>
            {% endif %}
          {% endwith %}
        {% endfor %}
      </tr>
    {% endfor %}

    <tr>
      <td class="font-bold bg-grey" colspan="2">Total Quantity</td>
      {% for itemname in items %}
        <td class="font-bold bg-grey align-right">{% get_item_quantity qty_dict itemname %}</td>
      {% endfor %}
    </tr>

  </table>

{% endblock %}
